"""
A simple toy program to display the workings of principal component
analysis or PCA.  The user can click to add points, then close the window.
The program will then show the points and the results of PCA.
"""

from genutils.point_maker import point_maker

# just some data to draw on a screen
datax = [0,1,2]
datay = [0,1,2]
# now we can click on the screen to add "data points"
points_list = point_maker(datax,datay)

import pylab
from genutils.simple_pca import pca
import numpy

# do the actual PCA
points_matrix = numpy.array(points_list)
signals, pc, var = pca(points_matrix)

# plot the results of the PCA
pylab.plot(points_matrix.T[0],points_matrix.T[1],'k.')
pylab.title('PCA example\n Principal Axes in green.')
pylab.plot(signals.T[0],signals.T[1],'r.')
# draw the principal component axes
pc1 = numpy.vstack(([0,0],pc[0]))
pc2 = numpy.vstack(([0,0],pc[1]))
pylab.plot(pc1.T[0],pc1.T[1],'g',linewidth=2)
pylab.plot(pc2.T[0],pc2.T[1],'g',linewidth=2)
pylab.ylim(-2,2)
pylab.xlim(-2,2)
pylab.legend(['Original Data','Rotated Data'])




